package com.example.demo.excel.listener;

import com.diboot.core.util.BeanUtils;
import com.diboot.core.util.ContextHelper;
import com.diboot.core.util.V;
import com.diboot.file.excel.listener.FixedHeadExcelListener;
import com.example.demo.entity.ProcurementOrderItem;

import com.example.demo.excel.model.ProcurementOrderItemImportModel;

import com.example.demo.service.ProcurementOrderItemService;


import java.util.List;
import java.util.Map;


public class ProcurementOrderItemImportListener extends FixedHeadExcelListener<ProcurementOrderItemImportModel> {

    /**
     * 自定义校验规则
     * @param dataModelList    待保存的数据
     * @param requestParams  请求参数
     */
    @Override
    protected void additionalValidate(List<ProcurementOrderItemImportModel> dataModelList, Map<String, Object> requestParams) {
      // 附加校验
    }

    /**
     * 保存数据
     * @param dataModelList 待保存的数据
     * @param requestParams 请求参数
     */
    @Override
    protected void saveData(List<ProcurementOrderItemImportModel> dataModelList, Map<String, Object> requestParams) {
      if (V.isEmpty(dataModelList)) {
        return;
      }
      List<ProcurementOrderItem> entityList = BeanUtils.convertList(dataModelList, ProcurementOrderItem.class);
      ContextHelper.getBean(ProcurementOrderItemService.class).createEntities(entityList);
    }
  }
